﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class hydevmanager_admin_edit_photo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["timeout"] == null)
            {
                Response.Redirect("login.aspx");
            }
            {
                load_photo();
            }
        }
    }

    protected void load_photo()
    {
        int idalbum = Convert.ToInt32(Request.QueryString.Get("idalbum"));
        grAllphoto.DataSource = DataAccess.ExeSQLToDataTable("Select * FROM dev_album_detail where idalbum=" + idalbum + "");
        grAllphoto.DataBind();
        //string str=Request.UserHostAddress.ToString();
    }

    protected void grAllphoto_click(object sen, CommandEventArgs e)
    {
        string Argvalue = e.CommandArgument.ToString();
        char[] ch = new char[] { '|' };

        string[] s = ITNLip.SplitString(Argvalue, ch);
        string id = s[0];
        string action = s[1];
        string photo_name = s[2];

        switch (action)
        {
            case "edit":
                txtEdit.Focus();
                txtEdit.Text = "";
                Session.Add("idptoto", s[0]);
                break;

            case "delete":
                int idphoto = Convert.ToInt32(s[0]);
                DataAccess.ExeNonSQL("DELETE FROM dev_album_detail WHERE idphoto=" + idphoto + "");

                string folder_album = Request.QueryString.Get("folder_album").ToString();
                delete_photoSelected(folder_album, photo_name);

                break;
        }

        load_photo();
    }

    protected void save_click(object sen, EventArgs e)
    {
        try
        {
            int idphoto = Convert.ToInt32(Session["idptoto"].ToString());
            DataAccess.ExeNonSQL("UPDATE dev_album_detail SET descriptions=N'" + txtEdit.Text + "' WHERE idphoto=" + idphoto + "");
            load_photo();
        }
        catch { }
    }

    protected void quaylai_click(object sen, EventArgs e)
    {
        Response.Redirect("admin_new_album.aspx");
    }

    protected void delete_photoSelected(string folder_name, string photo_name)
    {
        try
        {
            File.Delete(@Server.MapPath("~/files_upload/album/" + folder_name + "/" + photo_name));
        }
        catch { }
    }
}